/******************************************************************************/
package jamie.org.sil.www.usxUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;



/******************************************************************************/
/**
   A file output stream.
   <p>

   This is intended as a base class, with specific file output streams
   inheriting from it.
   <p>

   The inheriting classes may wish to implement <i>writeHeader</i> and
   <i>writeTrailer</i> from the base class -- see that for details.
**/
   

public class MyOutputStreamFile extends MyOutputStream
{
  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                                 Public                                 **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /**
     Constructor.

     @param filePath

     @param encoding
     
     @param headerAndTrailerWriter Writes header and trailer to the stream.  May
            be null if no header or trailer is required.
  */

  public MyOutputStreamFile (String filePath,
                             String encoding,
                             OutputStreamHeaderAndTrailerWriter headerAndTrailerWriter) throws IOException
  {
    super();
    m_Encoding = encoding;
    m_Name = filePath;
    m_HeaderAndTrailerWriter = headerAndTrailerWriter;
  }


  /****************************************************************************/
  /**
     Sets the file path.
     
     @parm filePath File path.
   */
  
  public void setFilePath (String filePath) 
  { 
    m_Name = filePath; 
  }
  




  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                               Protected                                **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /* Opens the stream. */
  
  @Override protected void doOpen () throws IOException
  {
    m_OutputStream =
      new BufferedWriterWithUndo(new OutputStreamWriter(new FileOutputStream(m_Name), m_Encoding));
  }
}
